package com.example.demo.sys.menu.service;

import com.example.demo.base.BaseService;
import com.example.demo.sys.menu.dao.SysMenuDao;
import com.example.demo.sys.menu.entity.SysMenu;
import com.example.demo.sys.user.entity.SysUser;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author haocj
 * 用户service
 */
@Service
public class SysMenuService extends BaseService<SysMenu, SysMenuDao> {

    @Resource
    private SysMenuDao sysMenuDao;

    /**
     * 查询菜单信息，上级菜单名称
     *
     * @param sysMenu
     * @return
     */
    @Override
    public SysMenu get(SysMenu sysMenu) {
        SysMenu sys = super.get(sysMenu);
        SysMenu menu = null;
        if (sys.getParentId() != null) {
            menu = super.get(sys.getParentId());
        }
        if (menu != null) {
            sys.setParentName(menu.getName());
        }
        return sys;
    }

    /**
     * 批量删除菜单信息
     *
     * @param ids
     */
    @Transactional(readOnly = false, rollbackFor = Exception.class)
    public void delete(String[] ids) {
        sysMenuDao.delete(ids);
    }
}
